package com.qezhhnjy.bilibili.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.qezhhnjy.bilibili.entity.Payment;

/**
 * @author zhaoyangfu - 2021/4/3 15:14
 */
public interface PaymentService extends IService<Payment> {
    String paymentInfoOK(int id);

    String paymentInfoTimeout(int id) throws Exception;

    void testTransaction() throws Exception;

    // 服务熔断
    @HystrixCommand(
            fallbackMethod = "paymentCircuitBreakerFallback",
            commandProperties = {
                    // 是否开启断路器
                    @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
                    // 请求次数
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
                    // 时间窗日期
                    @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
                    // 失败率达到多少后跳闸
                    @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"),
            }
    )
    String paymentCircuitBreaker(int id);
}
